package a09_贪心算法;

import java.util.Arrays;

/**
 * <p>
 * a17_用最少数量的箭引爆气球复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/4/23
 */
public class a17_用最少数量的箭引爆气球复习3 {

    //  -----         result=1
    //    -----       result=1
    //     -----      result=1
    //
    //

    //  -----         result=1
    //    -----       result=1
    //        -----   result=2
    //
    //

    //  -----         result=1
    //        -----   result=2
    //          ----- result=2
    //
    //

    public static void main(String[] args) {
        int[][] points = new int[][]{{-2147483646,-2147483645},{2147483646,2147483647}};
        System.out.println(findMinArrowShots(points));
    }

    public static int findMinArrowShots(int[][] points) {
        Arrays.sort(points,(point1,point2) -> {
            if(point1[0] != point2[0]){
                return point1[0] > point2[0] ? 1 : -1;
            }else {
                return point1[1] > point2[1] ? 1 : -1;
            }
        });

        int result = 1;
        for (int i = 1; i < points.length; i++) {
            if(points[i][0] > points[i-1][1]){
                result++;
            }else {//你和上一个公用一把剑，那么你右边界也要和他一致
                points[i][1] = Math.min(points[i-1][1], points[i][1]);
            }
        }
        return result;
    }
}
